<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <input type="text"> <button>是否为两位数</button>
    </div>
</body>
<script>
    //获取input框
    var input = document.querySelector("input")
    console.log(input)
    var button = document.querySelector("button")
    console.log(button)
    for (var i = 0; i < input.length; i++) {
        //限制输入的内容
        input.onkeyup = function () {
            this.value = this.value.replace(/^[\d]/,'')
        }
    }
    //点击按钮
    //定义一个变量先将input框的value赋值   定义一个变量在将值得长度赋值
    button.onclick = function () {
            console.log("点击事件")
            //定义变量提取输入内容的长度
            var neirong = input.value
            var chang = neirong.length
            //当长度等于等于二的时候 写三元运算符
            alert(chang == 2 ? '√是两位数' : "这是" + chang + '位数')
        }
</script>

</html>
<style>
    div {
        text-align: center;
    }
</style>